#!/bin/sh
#

PING=/sbin/ping
IFCONFIG=/sbin/ifconfig
ARP=/usr/sbin/arp
GREP=/usr/bin/grep
AWK=/usr/bin/awk

#
# Find the broadcast addresses to work with.
#
BROADCAST=`$IFCONFIG | $GREP broadcast | $AWK '{ print $6 }'`

#
# Ping each broadcast address 1 time.
#
for b in $BROADCAST; do
    $PING -c 1 $b 2>/dev/null >/dev/null
done

#
# Check the arp table for the address we want.
#
$ARP -an | $AWK 'BEGIN { FS="[()]| at | on " } { print $2, $4 }' | $AWK 'BEGIN { FS="[ :]" } { printf "%s %02s:%02s:%02s:%02s:%02s:%02s\n", $1, $2, $3, $4, $5, $6, $7 }' | $GREP -i $1 | $AWK '{ print $1 }'
